package com.lnsf.bookstore.web.topic.controller;

import com.lnsf.bookstore.common.annotation.IgnoreAuth;
import com.lnsf.bookstore.common.annotation.LoginUser;
import com.lnsf.bookstore.common.controller.ApiBaseAction;
import com.lnsf.bookstore.web.topic.service.ApiTopicService;
import com.lnsf.bookstore.web.topic.vo.ApiTopic;
import com.lnsf.bookstore.web.topicBook.service.ApiTopicBookService;
import com.lnsf.bookstore.web.user.vo.ApiUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/topic")
public class ApiTopicController extends ApiBaseAction{
    @Autowired
    private ApiTopicService apiTopicService;
    @Autowired
    private ApiTopicBookService apiTopicBookService;

    /**
     */
    @IgnoreAuth
    @RequestMapping("list")
    public Object list(@LoginUser ApiUser loginUser, @RequestParam(value = "page", defaultValue = "1") Integer page,
                       @RequestParam(value = "size", defaultValue = "10") Integer size) {
        Map param = new HashMap();
        param.put("page", page);
        param.put("limit", size);
        param.put("sidx", "id");
        param.put("order", "desc");
        //查询列表数据
        List<ApiTopic> topicList = apiTopicService.queryList(param);

        return toResponsSuccess(topicList);
    }

    /**
     */
    @IgnoreAuth
    @RequestMapping("detail")
    public Object detail(@LoginUser ApiUser loginUser, Integer id) {
        ApiTopic topicEntity = apiTopicService.queryObject(id);
        return toResponsSuccess(topicEntity);
    }
}
